<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>配餐配货管理-医疗器械</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="/apply_assets/css/bootstrap.min.css" rel="stylesheet">
    <link href="/apply_assets/css/style.css" rel="stylesheet">
    <link href="/apply_assets/css/font-awesome.css" rel="stylesheet">
    <link rel="stylesheet" href="/plugins/SweetAlert/sweetalert.css" />
</head>

<body>
    <div class="container-fluid">
        <div class="om-ctl-mes">
            <div class="title">
                <div class="col-xs-12"><span class="fa fa-list-ul"> 配餐配货管理</span><b class="fa fa-caret-right"></b><i>医疗器械</i></div>
            </div>
            <div class="seltemple peihuo-seltemple">
                <div class="col-xs-12">
                    <form class="form-inline">
                    <div class="col-xs-3 mes-group"><label>部门</label><select name="department1" id="department"><option value="0">不限</option><?foreach($tDIDatas as $tDRow){?><option value="<?=$tDRow['num']?>" <?if($Department == $tDRow['num'])echo 'selected';?>><?=$tDRow['introduce']?></option><?}?></select></div><div class="col-xs-3 mes-group"><label>服务状态</label><select name="statusid" id="status"><option value="0">全部</option><option value="1" <?= $statusid==1? 'selected':''; ?> >申报中</option><option value="3"<?= $statusid==3? 'selected':''; ?> >已服务</option></select></div>
                    <div class="col-xs-3 mes-btn off-btn"><p id="off-btn" style="width:90px">新增</p></div>
                    </form>
                </div>
            </div>
            <div  class="mes-conttent col-xs-12">
                <table class="table off-table">
                  <thead>
                    <tr>
                    <th>编号</th>
                    <th>部门名称</th>
                    <th>申请物品</th>
                    <th>服务类型</th>
                    <th>数量</th>
                    <th>申请时间</th>
                    <th>原因</th>
                    <th>操作人员</th>
                    <th>是否服务</th>
                    </tr>
                  </thead>
                 <tbody>
                    <?foreach($tDatas as $key => $Data){?>
                    <tr>
                        <td><?=$key+1?></td>
                        <td><?=$Data['departmnt']?></td>
                        <td><?=$Data['rep_name']?></td>
                        <td><?=$Data['rep_type']==1?'购买':'报修'?></td>
                        <td><?=$Data['rep_sapre']?></td>
                        <td><?=$Data['rep_time']?></td>
                        <td><?=$Data['rep_rea']?></td>
                        <td><?=$Data['name']?></td>
                        <td><?if($Data['rep_status']==1){?>申报中<?}elseif($Data['rep_status']==2){?><button id="cg" onclick="purchase(<?=$Data['rep_id']?>)">确认服务</button><?}else{?>已服务<?}?></td>
                    </tr>
                    <?}?>
                </tbody>
              </table>
                <?=$tShow?>
            </div>
        </div>
    </div>
        <script type="text/javascript" src="/apply_assets/js/jquery.min.js"></script>
<script src="/plugins/SweetAlert/sweetalert.min.js"></script><!--alert插件-->
<script src="/js/jquery.form.js"></script><!--form表单插件-->
<script>
function purchase(repid){
    $.post('/admin_apply/upstatus',{id:repid},function(obj){
        cg_alert_add(obj,'/admin_apply/report','/admin_apply/report');
    });
}
   function searchinfo(){
              var statusid = $('#status').val();
              var department = $('#department').val();
             location.href="/admin_apply/report?statusid="+statusid+"&department_id="+department
    }
   $('select[name="statusid"]').change(function(){
        searchinfo();
   });
      function searchinfo1(){
              var statusid = $('#status').val();
              var department = $('#department').val();
             location.href="/admin_apply/report?statusid="+statusid+"&department_id="+department
    }
    $('select[name="department1"]').change(function(){
        searchinfo1();
    });
$(function(){
//提交
    var options={
        beforeSubmit : showRequest,    // 提交前的回调函数
        success : showResponse,    // 提交后的回调函数
        dataType : "json",    // html（默认）、xml、script、json接受服务器端返回的类型
        timeout : 3000    // 限制请求的时间，当请求大于3秒后，跳出请求
    }
    function showRequest(formData, jqForm, options){
        return true;
    }
    function showResponse(responseText,statusText){
        cg_alert_add(responseText,'/admin_apply/report','/admin_apply/reportadd');
    }
function cg_alert_add(obj,list_url,add_url){
    if(obj.status == 1){
        swal({
            title: obj.msg,
            confirmButtonText:'继续添加',
            confirmButtonColor: "#DD6B55",
            showCancelButton: true,
            cancelButtonText:'返回列表',
            type: "success",
        },function(isConfirm){
            if (isConfirm) {
                location.href = add_url;
            }else{
                location.href = list_url;
            }
        });
    }else{
        swal(obj.msg,'','error');
    }

}
    var offalert="<div class='off-alert'></div>",
        html = "<div class='mark'></div>"
                +"<form method='post' class='form-inline addform' action='/admin_apply/reportadd' class='editDepartments'>"
               +"<div class='off-alert instrnew-alert'>"
                  +"<h3>新增记录<span id='close'>×</span></h3>"
                  +"<div class='form-content'><form><label>器械名称</label><input type='text' name='repname' placeholder='请输入' style='width:160px'><label>数量</label><input type='text' name='repnum' placeholder='请输入' style='width:60px'><label>服务类型</label><input type='radio' name='reptype' value='2' checked>报修　<input type='radio' name='reptype' value='1'>购买</form></div>"
          +"<div class='col-xs-12'><div class='col-xs-4'>原因</div><div class='col-xs-8'><textarea name='reptrea'></textarea></div></div>"
          +"<div class='btns'><button type='button' id='add-btn'>保存</button><button type='button' id='addcancle'>取消</button></div>"
          +"</div>"
                    +"</form>";
       $("body").prepend($(html))
    $(".mark").css("height",$(document).height()+"px")      
   $(".mark").addClass('hidden')    
   $(".off-alert").addClass('hidden')
      $("#off-btn").click(function(){
           $('.mark').show()
           $('.off-alert').show()
           $(".off-alert").removeClass('hidden')
           $(".mark").removeClass('hidden')
            $('#add-btn').click(function(){
                $('.addform').ajaxSubmit(options);
            });       
       
     })
    $('#addcancle').click(function(){
        location.href="/admin_apply/report";
    });
    $("#close").click(function(){
           $('.mark').hide()
           $('.off-alert').hide()
           $(".off-alert").addClass('hidden')
           $(".mark").addClass('hidden')
     })
})
$('#search').click(function(){
    $('.form').submit();
});

/*获取地址栏参数*/
function GetQuery(key){
    var search = location.search.slice(1);//得到get方式提交的查询字符串
    var arr = search.split("&");
    for(var i = 0; i < arr.length; i++){
        var ar = arr[i].split("=");
        if(ar[0] == key){
            return ar[1];
        }
    }
}

$('select[name="department"]').change(function(){
    var department_id = $(this).val();
    $.post('/admin_appraise',{department_id:department_id},function(obj){
        $('select[name="supportworker"]').remove();
        if(obj.status == 1){
            var data = obj.data;
            var html = (
                '<select name="supportworker">'
            );
            $.each(data,function(key,row){
                html += '<option value="'+row.id+'">'+row.name+'</option>';
            }); 
            html += '</select>';
            html += '<input type="hidden" name="tId" value="" class="tId"/>'
            $('.supportworker_name').append(html);
        }
    });
});
function sel(data){
    $('select[name="supportworker"]').remove();
    var html = (
        '<select name="supportworker">'
    );
    html += '<option value="'+data.w_id+'">'+data.name+'</option>';
    html += '</select>';
    $('.supportworker_name').append(html);
}
function editTrain(){
    $('#modal_box1').modal('toggle');
    var t_id = $(this).attr('data');
    alert(t_id);
}
var tId = '';
$('.edit').each(function(){
    $(this).click(function(){
        $('#modal_box1').modal('toggle');
        $('.editUser').click(function(){
            var edit_data = $('form[class="editTrain"]').serialize();
            $.post('/admin_apply/reportadd',edit_data,function(obj){alert(obj.msg);location.href="/admin_apply/report";});
        });
    });
});
function addUser(){
    var data = $('.addTrain').serialize();
    $.post('/admin_apply/reportadd',data,function(obj){
        alert(obj);
        if(obj.status == 1){
            alert(obj.msg);location.href="/admin_apply/report";
        }
        alert(obj.msg);return;
    });
}
    var color="#eeeeee";
    $("#table_list tr:odd td").css("background-color",color);  //改变偶数行背景色
    /* 把背景色保存到属性中 */
    $("#table_list tr:odd").attr("bg",color);
</script>
</body>
</html>
